import 'package:flutter/material.dart';

import '../provider/theme_provider.dart';
import '../util/screen_utils.dart';

extension BuildContextExtension on BuildContext {
  BiliNavigationBar commonStatusBar({Widget? child}) {
    return BiliNavigationBar(
      statusStyle: isDarkTheme(this)
          ? StatusStyle.LIGHT_CONTENT
          : StatusStyle.DARK_CONTENT,
      color: Theme.of(this).primaryColor,
      child: child,
    );
  }
}

class BiliNavigationBar extends StatefulWidget {
  final Widget? child;
  final double height;
  final Color color;
  final StatusStyle statusStyle;

  const BiliNavigationBar(
      {super.key,
      this.child,
      this.statusStyle = StatusStyle.DARK_CONTENT,
      this.height = 48,
      this.color = Colors.white});

  @override
  State<StatefulWidget> createState() {
    return BiliNavigationBarState();
  }
}

class BiliNavigationBarState extends State<BiliNavigationBar> {
  @override
  void initState() {
    super.initState();
    //设置状态栏
    changeStatusBar(color: widget.color, statusStyle: widget.statusStyle);
  }

  @override
  Widget build(BuildContext context) {
    var padding = MediaQuery.of(context).padding;
    //状态栏高度
    var statusBarHeight = padding.top;
    //屏幕的宽度
    var width = MediaQuery.of(context).size.width;
    return Container(
      color: widget.color,
      height: statusBarHeight + widget.height,
      width: width,
      padding: EdgeInsets.only(top: statusBarHeight),
      child: widget.child,
    );
  }
}
